package com.seckill.canal;

import com.seckill.goods.pojo.Sku;
import com.seckill.page.feign.SkuPageFeign;
import org.springframework.beans.factory.annotation.Autowired;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * @program: seckill-parent
 * @description: sku表的增删改监控
 * @author: zhanghz001
 * @create: 2021-06-25 13:56
 **/

// @CanalTable(value = "tb_sku")
// @Component
public class ZhzSkuHandler implements EntryHandler<Sku> {
    @Autowired
    private SkuPageFeign skuPageFeign;
    
    /***
     * 增加数据
     * @param sku
     */
    @Override
    public void insert(Sku sku) {
        try {
            if ("2".equalsIgnoreCase(sku.getStatus())) {
                skuPageFeign.html(sku);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            
        }
        // System.out.println("===========insert:" + sku);
    }
    
    @Override
    public void update(Sku before, Sku after) {
        try {
            if ("2".equalsIgnoreCase(before.getStatus())
                    && "1".equalsIgnoreCase(after.getStatus())) {
                //删除静态页
                skuPageFeign.delHtml(after.getId());
            } else if ("1".equalsIgnoreCase(before.getStatus())
                    && "2".equalsIgnoreCase(after.getStatus())) {
                //生成静态页
                skuPageFeign.html(after);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            
        }
        // System.out.println("===========update‐before:" + before);
        // System.out.println("===========update‐after:" + after);
    }
    
    @Override
    public void delete(Sku sku) {
        try {
            
            skuPageFeign.delHtml(sku.getId());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            
        }
        // System.out.println("===========delete:" + sku);
    }
}
